package com.pro.addresslist.tools;

import org.json.JSONObject;

import android.content.Context;

import com.android.volley.VolleyError;
import com.android.volley.Response.ErrorListener;
import com.android.volley.Response.Listener;
/**
 * @author leekh
 * */
public abstract class VolleyInterface {
	public Context mContext;
	public static Listener<JSONObject> mjsonObjListener;
	public static ErrorListener mErrorListtener;
	
	public VolleyInterface(Context context, Listener<JSONObject> listener, ErrorListener errorListener) {
		this.mContext = context;
		this.mjsonObjListener = listener;
		this.mErrorListtener = errorListener;
	}
	 //String way
	public abstract void onMySuccess(JSONObject result);
	public abstract void onMyError(VolleyError error);
	
	//Object way
	public ErrorListener errorListener() {
		mErrorListtener = new ErrorListener() {

			@Override
			public void onErrorResponse(VolleyError error) {
				onMyError(error);
			}
		};
		return mErrorListtener;
	}	
	public Listener<JSONObject> jsonObjectListener() {
		mjsonObjListener = new Listener<JSONObject>() {

			@Override
			public void onResponse(JSONObject response) {
				onMySuccess(response);
			}
		};
		return mjsonObjListener;
	}
}
